﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace YahtzeeAspTest.Model
{
    public class ScoreTable
    {
        /*public int MyProperty { get; set; }
        public int MyProperty { get; set; }
        public int MyProperty { get; set; }
        public int MyProperty { get; set; }
        public int MyProperty { get; set; }
        public int MyProperty { get; set; }
        public int MyProperty { get; set; }
        public int MyProperty { get; set; }
        public int MyProperty { get; set; }
        public int MyProperty { get; set; }*/

        public List<Score> listeScore;

       
        public ScoreTable()
        {
            listeScore.Add(new Score(1, "un", false, true));
            listeScore.Add(new Score(1, "deux", false, true));
            listeScore.Add(new Score(1, "tois", false, true));
            listeScore.Add(new Score(1, "quatre", false, true));
            listeScore.Add(new Score(1, "cinq", false, true));
            listeScore.Add(new Score(1, "six", false, true));
            listeScore.Add(new Score(2, "yams", false, true));
            listeScore.Add(new Score(2, "grande suite", false, true));
            listeScore.Add(new Score(2, "petite suite", false, true));
            listeScore.Add(new Score(2, "carré", false, true));
            listeScore.Add(new Score(2, "full", false, true));
            listeScore.Add(new Score(2, "brelant", false, true));
            listeScore.Add(new Score(3, "chance", false, true));
           
        }

        //http://en.wikipedia.org/wiki/Yahtzee
        public int returnTheScoreOfThreeOfAKind(List<Dice> listdice)
        {
            return 10;
        }
        public int returnTheScoreOfFourOfAKind(List<Dice> listdice)
        {
            return 10;
        }
        public int returnTheScoreOfFullHouse(List<Dice> listdice)
        {
            return 10;
        }
        public int returnTheScoreOfSmallStraight(List<Dice> listdice)
        {
            return 10;
        }
        public int returnTheScoreOfLargeStraight(List<Dice> listdice)
        {
            return 10;
        }
        public int returnTheScoreOfYahtzee(List<Dice> listdice)
        {
            return 10;
        }
        public int returnTheScoreOfChance(List<Dice> listdice)
        {
            return 10;
        }

        public Score getScoreByName(string name)
        {
            for (int countScoreTable = 0; countScoreTable < listeScore.Count; countScoreTable++)
            {
                if (listeScore[countScoreTable].name == name) return listeScore[countScoreTable];
            }
            return null;
        }

        public void returnValideCombineson(List<Dice> listdice)
        {
            int conterFirstCategory = 0;
            while (listeScore[conterFirstCategory].category == 1)           
            {
                for (int i = 0; i < listdice.Count(); i++)
                {
                    if (listdice[i].Value==(conterFirstCategory+1))
                    {
                        listeScore[conterFirstCategory].scorePossible = false;
                    }
                }
                conterFirstCategory++;
            }           
            int countSameDice = 0;
            int countDifferentDice = 0;
            for (int j = 0; j<listdice.Count-1; j++)
            {
               for (int k = 1; k < listdice.Count; k++)
               {
                   if (listdice[j].Value == listdice[k].Value)
                   {
                       countSameDice++;
                   }
                   if (listdice[j].Value != listdice[k].Value)
                   {
                       countDifferentDice++;
                   }
               }
            }
            if (countSameDice == 5)
            {
                getScoreByName("yams").scorePossible=true;
                getScoreByName("carré").scorePossible = true;
                getScoreByName("brelant").scorePossible = true;
            }
            else if (countSameDice == 4)
            {
                getScoreByName("carré").scorePossible = true;
                getScoreByName("brelant").scorePossible = true;
            }
            else if (countSameDice == 3)
            {                
                getScoreByName("brelant").scorePossible = true;
                if (countDifferentDice == 2) getScoreByName("full").scorePossible = true;
            }
            else if (countSameDice == 2)
            {
                if (countDifferentDice == 2) getScoreByName("full").scorePossible = true;
                if (countDifferentDice == 4) getScoreByName("petite suite").scorePossible = true;
            }
            else if (countSameDice == 0)
            {
                getScoreByName("grande suite").scorePossible = true;
            }
        }
    }
}